﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Web.UI;
using System.Security.Cryptography;

/// <summary>
/// Summary description for CommonFuns
/// </summary>
public class CommonFuns
{
	public CommonFuns()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static void ShowPopUpMsg(Page page, string msg)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("alert('");
        sb.Append(msg.Replace("\n", "\\n").Replace("\r", "").Replace("'", "\\'"));
        sb.Append("');");
        ScriptManager.RegisterStartupScript(page.Page, page.GetType(), "showalert", sb.ToString(), true);
    }

    public static string HashSHA1(string value)
    {
        SHA1 sha1 = SHA1.Create();
        byte[] hashData = sha1.ComputeHash(Encoding.Default.GetBytes(value));

        //create new instance of StringBuilder to save hashed data
        StringBuilder returnValue = new StringBuilder();

        //loop for each byte and add it to StringBuilder
        for (int i = 0; i < hashData.Length; i++)
        {
            returnValue.Append(hashData[i].ToString());
        }

        // return hexadecimal string
        return returnValue.ToString();
    }
}